home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / util / shell / dbGoodies.lha / goodies / cprompt.c next >
Encoding:
C/C++ Source or Header  |  1995-03-03  |  1.8 KB  |  68 lines

  1. /*
  2.     cprompt - print out actual directory name, i.e. if you are in SYS:Tools/Commodities then
  3.     cprompt will result "Commodities". It is reentrant and therefore a resident program. You
  4.     can use it in your shell's prompt like this: PROMPT "`cprompt`>" if you load cprompt as a resident;
  5.     this will increase the execution speed.
  6.                                                             by Daniel Balster
  7.  
  8.     recompile it with: gcc -s -O9 -m68040 -nostdlib cprompt.c -o cprompt
  9. */
  10.  
  11. int _main (void) { return main(); }
  12. void __main (void) {}
  13.  
  14. #include <exec/exec.h>
  15. #include <inline/exec.h>
  16. #include <dos/dos.h>
  17. #include <inline/dos.h>
  18.  
  19. char *versionstring = "$VER: cprompt 1.1 (26.2.1995) by Daniel Balster";
  20. struct ExecBase *SysBase = NULL;
  21. struct DosLibrary *DOSBase = NULL;
  22.  
  23. int main (void)
  24. {
  25.     int colormode = 0;
  26.  
  27.     if (SysBase==NULL) SysBase = (struct ExecBase *) *(ULONG*)4;
  28.     if (DOSBase==NULL) DOSBase = (struct DosLibrary *) OpenLibrary ("dos.library",37L);
  29.  
  30.     if (DOSBase)
  31.     {
  32.         BPTR curdirlock = CurrentDir(0);
  33.         char strbuf[256];        /* CHECK STACKSIZE ELSE THIS CRASH YOUR MACHINE */
  34.         int i = 0;
  35.  
  36.         if (NameFromLock (curdirlock,strbuf,256))
  37.         {
  38.             if (strbuf[0]=='N')
  39.             if (strbuf[1]=='e')
  40.             if (strbuf[2]=='t')
  41.             if (strbuf[3]=='w')
  42.             if (strbuf[4]=='o')
  43.             if (strbuf[5]=='r')
  44.             if (strbuf[6]=='k')
  45.             if (strbuf[7]==':')
  46.                 colormode = 1;
  47.  
  48.             while (strbuf[i++]);                /* do a simple strlen() */
  49.             while ((strbuf[--i]!='/') && (strbuf[i]!=':') && (i>=0));    /* scan for / and : */
  50.             if (!strbuf[++i]) i=0;                /* next character is a zero -> print whole string ! */
  51.  
  52.             if (colormode==1) PutStr("\033[32m");
  53.  
  54.             PutStr (&(strbuf[i]));            /* print out this result */
  55.  
  56.             if (colormode) PutStr("\033[0m");
  57.         }
  58.         else PrintFault (IoErr(),0);
  59.  
  60.         CurrentDir (curdirlock);
  61.         CloseLibrary ((struct Library*)DOSBase);
  62.         DOSBase = NULL;
  63.     }
  64.     else return RETURN_FAIL;
  65.  
  66.     return RETURN_OK;
  67. }
  68.